package com.yike.user.controller;

import com.yike.user.entity.PayChannel;
import com.yike.user.param.PayChannelParam;
import com.yike.user.service.PayChannelService;
import com.yike.user.vo.PayChannelVo;
import lombok.extern.slf4j.Slf4j;
import com.yike.user.param.PayChannelPageParam;
import com.yike.common.base.BaseController;
import com.yike.common.api.ApiResult;
import com.yike.common.pagination.Paging;
import com.yike.common.api.IdParam;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.enums.OperationLogType;
import com.yike.common.api.Add;
import com.yike.common.api.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 支付渠道 控制器
 *
 * @author Sakura
 * @since 2024-11-15
 */
@Slf4j
@RestController
@RequestMapping("/platform/payChannel")
@Module("user")
@Api(value = "支付渠道API", tags = {"平台服务商通道"})
public class PayChannelController extends BaseController {

    @Autowired
    private PayChannelService payChannelService;

    /**
     * 添加支付渠道
     */
    @PostMapping("/add")
    @OperationLog(name = "添加服务商", type = OperationLogType.ADD)
    @ApiOperation(value = "添加服务商", response = ApiResult.class)
    public ApiResult<Boolean> addPayChannel(@Validated(Add.class) @RequestBody PayChannelParam payChannelParam) throws Exception {
        boolean flag = payChannelService.savePayChannel(payChannelParam);
        return ApiResult.result(flag);
    }

    /**
     * 修改支付渠道
     */
    @PostMapping("/update")
    @OperationLog(name = "修改服务商", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改服务商", response = ApiResult.class)
    public ApiResult<Boolean> updatePayChannel(@Validated(Update.class) @RequestBody PayChannelParam payChannelParam) throws Exception {
        boolean flag = payChannelService.updatePayChannel(payChannelParam);
        return ApiResult.result(flag);
    }

    /**
     * 删除支付渠道
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除服务商", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除服务商", response = ApiResult.class)
    public ApiResult<Boolean> deletePayChannel(@PathVariable("id") Long id) throws Exception {
        boolean flag = payChannelService.deletePayChannel(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取支付渠道详情
     */
    @GetMapping("/info/{id}")
    @OperationLog(name = "服务商详情", type = OperationLogType.INFO)
    @ApiOperation(value = "服务商详情", response = PayChannelVo.class)
    public ApiResult<PayChannelVo> getPayChannel(@PathVariable("id") Long id) throws Exception {
        PayChannelVo payChannelVo = payChannelService.getPayChannel(id);
        return ApiResult.ok(payChannelVo);
    }

    /**
     * 支付渠道分页列表
     */
    @PostMapping("/getPageList")
    @OperationLog(name = "服务商分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "服务商分页列表", response = PayChannelVo.class)
    public ApiResult<Paging<PayChannelVo>> getPayChannelPageList(@Validated @RequestBody PayChannelPageParam payChannelPageParam) throws Exception {
        Paging<PayChannelVo> paging = payChannelService.getPayChannelPageList(payChannelPageParam);
        return ApiResult.ok(paging);
    }

}

